package com.bestv.c2.task;

import com.bestv.c2.handler.DumpHandler;

import java.io.IOException;
import java.text.ParseException;

/**
 * Created by Henry on 15/9/2.
 */
public class DumpDataTask extends Task {
    private String dumpTables;
    private DumpHandler handler;

    @Override
    public void execute() {
        logger.info("Starting csv data dump task...");

        try {
            String[] tables = dumpTables.split(",");
            for (String table : tables) {
                long time = System.currentTimeMillis();
                handler.setTable(table);
                handler.handle();
                long length = System.currentTimeMillis() - time;
                logger.info("End dump data for: {}, times(ms): {}.", handler.getExportFilePath(), length);
            }
        } catch (IOException e) {
            logger.error("Error on IO.", e);
        } catch (ParseException e) {
            logger.error("Error on Parse.", e);
        }

        logger.info("Finish csv data dump task.");
    }

    public String getDumpTables() {
        return dumpTables;
    }

    public void setDumpTables(String dumpTables) {
        this.dumpTables = dumpTables;
    }

    public DumpHandler getHandler() {
        return handler;
    }

    public void setHandler(DumpHandler handler) {
        this.handler = handler;
    }
}
